Legendre 2-Point Statistics


In [22]:
% matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import scipy as sp
import scipy.ndimage as si
import pymks

In [3]:
from pymks.datasets import make_cahn_hilliard
from pymks.bases import LegendreBasis

In [6]:
t_steps = 10

size =(50, 50)
Data = np.zeros(size + (t_steps,))
#for ii in range(t_steps):

In [77]:
X, y = make_cahn_hilliard(50, (50, 50))

In [78]:
from pymks.tools import draw_concentrations

#draw_concentrations(X[0], y[0])

plt.figure()
plt.imshow(X[0])
plt.colorbar()
plt.figure()
plt.imshow(y[0])
plt.colorbar()


Out[78]:
<matplotlib.colorbar.Colorbar instance at 0x00000000173511C8>

In [10]:
from pymks.datasets.cahn_hilliard_simulation import CahnHilliardSimulation

N = 50

phi0 = 0.01 * (2 * np.random.random((N, N)) - 1)
Data[:, :, 0] = phi0.copy()
ch = CahnHilliardSimulation()
for ii in range(t_steps - 1):
    ch.run(Data[:, :, ii])
    Data[:, :, ii + 1] = ch.response

In [13]:
for ii in range(t_steps):
    if ii == 0 or ii == (t_steps - 1):
        plt.figure()
        plt.imshow(Data[:, :, ii])
        plt.colorbar()



In [112]:
n_states = 6
LegBasis = LegendreBasis(n_states=n_states, domain=[-1, 1])

In [107]:
X_end = Data[:, :, -1]# Last time step
X_start = Data[..., 0]
X_end_ = LegBasis.discretize(X_end)
X_start_ = LegBasis.discretize(X_start)
print np.unique(X_end.imag)
print len(np.unique(X_end.imag))


[ 0.]
1

In [108]:
FX_end_ = np.fft.fftn(X_end_, axes=(0, 1))
FX_start_ = np.fft.fftn(X_start_, axes=(0, 1))
print np.unique(FX_end_.imag)
print len(np.unique(FX_end_.imag))


[-6.0304639  -5.36428786 -5.05913309 ...,  5.05913309  5.36428786
  6.0304639 ]
12496

In [109]:
def new_coeffs(X_):
    n_states = X_.shape[-1]
    Niter = np.ceil((n_states + 1) / 2.)
    Nslice = n_states * (n_states + 1) / 2
    Mat = np.zeros((50, 50, 4, 4))
    tmp = [np.conj(X_) * np.roll(X_, i, axis=-1) for i in range(int(Niter))]
    return np.concatenate(tmp, axis=-1)[..., :Nslice]

In [110]:
# Think about normalization
FX_t_end = new_coeffs(X_end_)
FX_t_start = new_coeffs(X_start_)
print np.unique(FX_t_end.imag)
print len(np.unique(FX_t_end.imag))
print FX_t_start.shape


[ 0.]
1
(50L, 50L, 21L)

In [111]:
X_t_end = np.fft.irfftn(FX_t_end, axes=(0, 1))
X_t_start = np.fft.irfftn(FX_t_start, axes=(0, 1))
print np.unique(X_t_end.imag)
print len(np.unique(X_t_end.imag))


[ 0.]
1

In [105]:
from pymks import MKSKernelPCAModel

In [ ]:

Hello $x=0$ $$ X = 0$$

$$\sum_{n=0}^N$$

2-Point Statistics


In [ ]:
from pymks.stats import autocorrelate

? autocorrelate

In [ ]:


In [ ]:


In [ ]:

$$ m(h)_s = \sum_{l=0}^\infty a_{sl} P_l(h)$$
$$ f(h, h')_t = \sum_{s=0}^S m(h)_{s+t} m(h')_s $$
$$f(h, h')_t = \sum_{s=0}^S \sum_{l=0}^\infty \sum_{l'=0}^\infty a_{sl} P_l(h) a_{sl'} P_{l'}(h')$$
$$M(h)_k = \sum_{s=0}^S m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg)$$
$$M(h)_k = \sum_{s=0}^{S-1} m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) = \sum_{s=0}^{S-1} \sum_{l=0}^\infty a_{sl} P_l(h) exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) = \sum_{l=0}^\infty A_{kl} P_l(h)$$
$$ \sum_{k=0}^S \Bigg[\Bigg(\sum_{s=0}^S m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) \Bigg)^* \sum_{s=0}^S m(h')_s exp \Bigg ({\frac{2\pi i k' (s+t)}{S}}\Bigg) \Bigg] exp \Bigg ({\frac{-2\pi i k s}{S}}\Bigg)$$
$$ \sum_{k=0}^S \Bigg[\Bigg(\sum_{s=0}^S m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) \Bigg)^* \sum_{s=0}^S m(h')_s exp \Bigg ({\frac{2\pi i k' (s+t)}{S}}\Bigg) \Bigg] exp \Bigg ({\frac{-2\pi i k s}{S}}\Bigg)$$

In [ ]:


In [ ]:

$$ \sum_{k=0}^S \Bigg[\Bigg(\sum_{s=0}^S m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) \Bigg)^* \sum_{s=0}^S m(h')_s exp \Bigg ({\frac{2\pi i k' s}{S}}\Bigg) exp \Bigg ({\frac{2\pi i k' t}{S}}\Bigg) \Bigg] exp \Bigg ({\frac{-2\pi i k s}{S}}\Bigg)$$
$$ \sum_{k=0}^S \Bigg[\Bigg(\sum_{s=0}^S m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) \Bigg)^* \sum_{s=0}^S m(h')_s exp \Bigg ({\frac{2\pi i k' s}{S}}\Bigg) exp \Bigg ({\frac{2\pi i k' t}{S}}\Bigg) \Bigg] exp \Bigg ({\frac{-2\pi i k s}{S}}\Bigg)$$
$$ \sum_{k=0}^S \Bigg[\Bigg(\sum_{s=0}^S m(h)_s exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) \Bigg)^* \sum_{s=0}^S m(h')_s exp \Bigg ({\frac{2\pi i k' s}{S}}\Bigg) \Bigg] exp \Bigg ({\frac{-2\pi i k s}{S}}\Bigg)$$
$$ f(h, h')_t = \frac{1}{S}\sum_{k=0}^S \Bigg[\Bigg(\sum_{s=0}^S \sum_{l=0}^\infty a_{sl} P_l(h) exp \Bigg ({\frac{2\pi i k s}{S}}\Bigg) \Bigg)^* \sum_{s=0}^S \sum_{l'=0}^\infty a_{sl'} P_l'(h') exp \Bigg ({\frac{2\pi i k' s}{S}}\Bigg) \Bigg] exp \Bigg ({\frac{-2\pi i k s}{S}}\Bigg)$$
$$\sum_{s=0}^S m(h)_{s+t} m(h')_s =\F^{-1} M(h)_k * ( M(h')_k)^*$$